$(function() {
	// 初始化滑动条
	$('.slider').slider({
		value: 0,
		min: 0,
		max: 2,
		step: 1,
		slide: function(event, ui) {
            alert(111);
		},
		change: function(event, ui) {
			// 滑块改变值时调用
		},
		stop: function(event, ui) {
			pauseSlider();
		}
	});
	// 初始化播放按钮
	$('#play').button({
		text: false,
		icons: { primary: "ui-icon-play" }
	}).click(function() {
		var val = $('.slider').slider('value'),
			max = $('.slider').slider('option', 'max');
		if (val === max) {
			resetSlider();
			playSlider();
		}
		var options;
		if ($(this).text() === "Play") {
			options = {
				label: "Pause",
				icons: { primary: "ui-icon-pause" }
			};
			playSlider();
		} else {
			options = {
				label: "Play",
				icons: { primary: "ui-icon-play" }
			};
			pauseSlider();
		}
		$(this).button("option", options);
	});
});
var timer;
	
function playSlider() { //播放事件
	clearInterval(timer);
	timer = setInterval(function() {
		var val = $('.slider').slider('value'),
		max = $('.slider').slider('option', 'max'),
		newVal = val < max ? val + 1 : 0;
		if (newVal === 0) {
			pauseSlider();
		} else {
			$('.slider').slider('value', newVal);
		}
	}, 200);
}
function pauseSlider() { //暂停事件
	clearInterval(timer);
	var options = {
		label: "Play",
		icons: { primary: "ui-icon-play" }
	};
	$('#play').button("option", options);
}

function resetSlider(max) {
	clearInterval(timer);
	var options = {
		label: "Play",
		icons: { primary: "ui-icon-play" }
	};
	$('#play').button("option", options);
	$('.slider').slider('value', 0);
    $('.slider').slider('option', 'max', max);
}
